{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "16334f66",
   "metadata": {},
   "outputs": [],
   "source": [
    "#时间填充\n",
    "import pandas as pd\n",
    "A603 = pd.read_csv('../data_process_yjy/4G_AFE_0603_0609.csv',index_col=0)\n",
    "A603['TimeStamp'] = A603['TimeStamp'].astype('datetime64[ns]')\n",
    "date_range = pd.date_range(\"2021-06-03 00:00:00\",\"2021-06-09 23:00:00\",freq='H')\n",
    "new_index = pd.MultiIndex.from_product([A603['UserLabel'].unique(),date_range],names=['UserLabel','TimeStamp'])\n",
    "A603_date = pd.DataFrame(index=new_index).reset_index()\n",
    "A603_new = pd.merge(A603_date,A603,how='left',on=['UserLabel','TimeStamp'])\n",
    "A603_new.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "19e3bddf",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "A610 = pd.read_csv(\"../data_process_yjy/4G_AFE_0610_0616.csv\",index_col=0)\n",
    "A610['TimeStamp'] = A610['TimeStamp'].astype('datetime64[ns]')\n",
    "date_range = pd.date_range(\"2021-06-10 00:00:00\",\"2021-06-16 23:00:00\",freq='H')\n",
    "new_index = pd.MultiIndex.from_product([A610['UserLabel'].unique(),date_range],names=['UserLabel','TimeStamp'])\n",
    "A610_date = pd.DataFrame(index=new_index).reset_index()\n",
    "A610_new = pd.merge(A610_date,A610,how='left',on=['UserLabel','TimeStamp'])\n",
    "A610_new.head(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cdd51647",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "A617 = pd.read_csv(\"../data_process_yjy/4G_AFE_0617_0623.csv\",index_col=0)\n",
    "A617['TimeStamp'] = A617['TimeStamp'].astype('datetime64[ns]')\n",
    "date_range = pd.date_range(\"2021-06-17 00:00:00\",\"2021-06-23 23:00:00\",freq='H')\n",
    "new_index = pd.MultiIndex.from_product([A617['UserLabel'].unique(),date_range],names=['UserLabel','TimeStamp'])\n",
    "A617_date = pd.DataFrame(index=new_index).reset_index()\n",
    "A617_new = pd.merge(A617_date,A617,how='left',on=['UserLabel','TimeStamp'])\n",
    "#A617_new.drop('Unnamed: 0',axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0f5df2f7",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "A624 = pd.read_csv(\"../data_process_yjy/4G_AFE_0624_0630.csv\",index_col=0)\n",
    "A624['TimeStamp'] = A624['TimeStamp'].astype('datetime64[ns]')\n",
    "date_range = pd.date_range(\"2021-06-24 00:00:00\",\"2021-06-30 23:00:00\",freq='H')\n",
    "new_index = pd.MultiIndex.from_product([A624['UserLabel'].unique(),date_range],names=['UserLabel','TimeStamp'])\n",
    "A624_date = pd.DataFrame(index=new_index).reset_index()\n",
    "A624_new = pd.merge(A624_date,A624,how='left',on=['UserLabel','TimeStamp'])\n",
    "#A624_new.drop('Unnamed: 0',axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "93c7af53",
   "metadata": {},
   "outputs": [],
   "source": [
    "#按周进行平移\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "A603_flag = A603_new.isnull().any(axis=1)\n",
    "A603_flag = A603_flag.values\n",
    "lens = len(A603_flag)\n",
    "print(lens)\n",
    "for i in range(0,lens):\n",
    "    print(i,\":\",A603_flag[i])\n",
    "    if(A603_flag[i]):\n",
    "        rows = i\n",
    "        for j in range(3,9):\n",
    "            A603_new.iloc[rows,j] = A610.iloc[rows,j]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fcb5870c",
   "metadata": {},
   "outputs": [],
   "source": [
    "#按日平移\n",
    "import pandas as pd\n",
    "A603_new[\"上行利用率PUSCH\"].fillna(method ='ffill', inplace = True)\n",
    "A603_new[\"下行利用率PDSCH\"].fillna(method ='ffill', inplace = True)\n",
    "A603_new[\"下行利用率PDCCH\"].fillna(method ='ffill', inplace = True)\n",
    "A603_new[\"有效RRC连接平均数\"].fillna(method ='ffill', inplace = True)\n",
    "A603_new[\"上行流量\"].fillna(method ='ffill', inplace = True)\n",
    "A603_new[\"下行流量\"].fillna(method ='ffill', inplace = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6387cc24",
   "metadata": {},
   "outputs": [],
   "source": [
    "#按本城市平均值平移\n",
    "A603_new[\"上行利用率PUSCH\"].fillna(A603_new[\"上行利用率PUSCH\"].mean(), inplace = True)\n",
    "A603_new[\"下行利用率PDSCH\"].fillna(A603_new[\"下行利用率PDSCH\"].mean(), inplace = True)\n",
    "A603_new[\"下行利用率PDCCH\"].fillna(A603_new[\"下行利用率PDCCH\"].mean(), inplace = True)\n",
    "A603_new[\"有效RRC连接平均数\"].fillna(A603_new[\"有效RRC连接平均数\"].mean(), inplace = True)\n",
    "A603_new[\"上行流量\"].fillna(A603_new[\"上行流量\"].mean(), inplace = True)\n",
    "A603_new[\"下行流量\"].fillna(A603_new[\"下行流量\"].mean(), inplace = True)\n",
    "A603.to_csv('4G_AFE_0603_0609.csv')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py37",
   "language": "python",
   "name": "py37"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
